package net.cathackers.devel.scmp.chat.impl.xmpp;
import net.cathackers.devel.scmp.config.impl.SCMPConstants;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;


public class XMPPDecoder extends CumulativeProtocolDecoder{

	@Override
	protected boolean doDecode(IoSession session, IoBuffer in,
			ProtocolDecoderOutput out) throws Exception {
		XMLCumulativeParser parser = (XMLCumulativeParser)session.getAttribute(SCMPConstants._PARSER_);
		parser.read(in);
		
        if (parser.doHaveMessages()) {
            for (String myStanza : parser.getMessages()) {
                out.write(myStanza);
            }
        }
        return !in.hasRemaining();
	}

}
